<template>
  <div>
    <h3>商家评论</h3>
    <div class="aa1">
      <el-card class="box-card">
        <h4>评论内容</h4>
        <div v-for="(item, i) in comment_list" :key="i" class="text item">
          <el-avatar :src="item.user_img"></el-avatar>
          {{ item.user_name }}：{{ item.content }} <br />
          发布时间：{{ item.create_time }}&emsp;&emsp;&emsp;
          <el-button @click="reply(item.id)">回复</el-button>
        </div>
      </el-card>
    </div>

    <el-dialog title="回复" :visible.sync="dialogFormVisible">
      <el-form>
        <el-form-item>
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="centent"
            style="width: 300px"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="comment_treply_on">确 定</el-button>
      </div>
    </el-dialog>

    <div class="aa2">
      <el-card class="box-card">
        <h4>回复内容</h4>
        <div v-for="(item, i) in comment_treply" :key="i" class="text item">
          <el-avatar :src="item.user_img"></el-avatar>
          {{ item.commentator }}回复了：{{ item.be_reviewed }} <br />
          回复内容：{{ item.content }}<br />
          发布时间：{{ item.send_time }}
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import Axios from "axios";
export default {
  name: "",
  data() {
    return {
      value1: null,
      textarea: "",
      comment_list: [],
      comment_treply: [],
      uid: "",
      dialogFormVisible: false,
      centent: "",
      cid: "",
      mid: "",
      uid: "",
      oid: this.$route.params.oid,
    };
  },
  props: {},

  components: {},

  created() {},

  mounted() {
    // 获取当前登录商家的信息
    Axios.get("http://127.0.0.1:8000/user/merchant/", {
      headers: { token: localStorage.getItem("token") || "" },
    }).then((res) => {
      this.mid = res.data.userinfo.id;
      console.log("获取登录商家的信息>>", res);
    });
    // 获取订单店铺的评论用户评论
    Axios.get("http://127.0.0.1:8000/comment/merchant_comment/", {
      headers: { token: localStorage.getItem("token") || "" },
    }).then((res) => {
      console.log("获取评论信息>>", res);
      this.comment_list = res.data.data;
      this.comment_treply = res.data.comment_treply;
    });
  },

  methods: {
    // 点击回复弹出
    reply(id) {
      this.dialogFormVisible = true;
      console.log("id>>>", id);
      this.cid = id;
    },
    // 评论回复
    comment_treply_on() {
      (this.dialogFormVisible = false),
        Axios.post("http://127.0.0.1:8000/comment/comment_treply/", {
          cid: this.cid,
          uid: this.uid,
          mid: this.mid,
          centent: this.centent,
        }).then((res) => {
          console.log("回复评论的响应>>", res);
          // this.comment_treply = res.data
          if (res.data.code == 200) {
            this.$notify({
              title: "成功",
              message: "回复评论成功",
              type: "success",
            });
          } else {
            this.$notify.error({
              title: "错误",
              message: res.data.msg,
            });
          }
          // 把信息添加到回复展示表
          Axios.post("http://127.0.0.1:8000/comment/comment_show/", {
            cid: this.cid,
            uid: this.uid,
            mid: this.mid,
            centent: this.centent,
          }).then((res) => {
            console.log("添加回复内容展示表的响应>>>", res);
          });
        });
      // 获取订单店铺的评论用户评论
      Axios.get("http://127.0.0.1:8000/comment/merchant_comment/", {
        headers: { token: localStorage.getItem("token") || "" },
      }).then((res) => {
        console.log("获取评论信息>>", res);
        this.comment_list = res.data.data;
        this.comment_treply = res.data.comment_treply;
      });
    },
  },

  computed: {},

  watch: {},

  directives: {},

  filters: {},
};
</script>

<style>
* {
  margin: 0;
}
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 480px;
}
.aa1 {
  float: left;
}
.aa2 {
  float: left;
}
</style>